package frontend.registration.controller;

import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

import frontend.registration.dao.DiscountManager;

public class DiscountController  extends ActionSupport 
{

	/**
	 * 
	 */
	private static final long serialVersionUID = 13434343L;
	private String discountCode ;
	private DiscountManager dm ;
	private String errorMsg ;
	private Float discount ;
	
	public DiscountController()
	{
		dm = new DiscountManager();
	}
	public String execute() 
	{
		
		Map<String,String> result = dm.getDiscountByCode(this.getDiscountCode());
		if(result.get("Error")!= null)
		{
			this.setErrorMsg(result.get("Error"));
			return ERROR ;
		}
		else
		{
			Map<String, Object> session = ActionContext.getContext().getSession();
			this.setDiscount(Float.parseFloat(result.get("discount")));
			session.put("cuoponCode", this.getDiscountCode());
		}
		return SUCCESS ;
	}
	/**
	 * @return the discountCode
	 */
	public String getDiscountCode() {
		return discountCode;
	}
	/**
	 * @param discountCode the discountCode to set
	 */
	public void setDiscountCode(String discountCode) {
		this.discountCode = discountCode;
	}
	/**
	 * @return the errorMsg
	 */
	public String getErrorMsg() {
		return errorMsg;
	}
	/**
	 * @param errorMsg the errorMsg to set
	 */
	public void setErrorMsg(String errorMsg) {
		this.errorMsg = errorMsg;
	}
	/**
	 * @return the discount
	 */
	public Float getDiscount() {
		return discount;
	}
	/**
	 * @param discount the discount to set
	 */
	public void setDiscount(Float discount) {
		this.discount = discount;
	}

}
